package com.action;


import java.net.URL;

import org.apache.commons.lang3.StringUtils;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {

	/** 
	* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么) 
	*/
	private static final long serialVersionUID = 1L;

	private String username;
	
	private String password;

	public String getPassword() {
		return password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public void validate() {
		
		System.out.println("-------------");
		URL url1 = ClassLoader.getSystemResource("");
		System.out.println("路径：：" + url1);
		if(url1 != null) {
			String proPath = StringUtils.substringBetween(url1.toString(),"file:/", "/target/classes/");
			System.out.println("项目路径：：" + proPath);
		}
		
		System.out.println("user.dir::" + System.getProperty("user.dir"));
		System.out.println("-------------");

		
		if(username == null || username.equals("")){
			this.addFieldError("username", "用户名不能为空");
		}
		if(password == null || password.equals("")){
			this.addFieldError("password", "密码不合法");
		}
	}
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		
		if(username != null && !username.equals("") && password != null && !password.equals("")){
			if(username.equals("anzi") && password.equals("123")){
				System.out.println("登录成功");
				System.out.println("欢迎你，thank you!!");
				return "loginSuccess";
			}else{
				return "loginFailure";
			}
		}
		return  "loginFailure";
	}
	
	
	
}
